package com.jdk.demo.io.so_sndbufDemo;

import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {

	public static void main(String[] args) throws Exception {
		Socket socket = new Socket();
		System.out.println("A client socket.getSendBufferSize()=" + socket.getSendBufferSize());
		socket.setSendBufferSize(1024);
		System.out.println("B client socket.getSendBufferSize()=" + socket.getSendBufferSize());
		socket.connect(new InetSocketAddress("localhost", 8888));
		OutputStream outputSteam = socket.getOutputStream();
		for (int i = 0; i < 500000; i++) {
			outputSteam.write(
					"123456789123456789123456789123456789123456789123456789123456789123456789123456789"
					.getBytes());
		}
		outputSteam.write("end!".getBytes());
		outputSteam.close();
		socket.close();
		// 用时8961
		// 如果改为socket.setSendBufferSize(1024)，用时7956，说明可以提高程序运行效率
	}

}
